package com.csdj.s3project.controller;


import com.csdj.s3project.common.CacheConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * 基本控制器
 */
public class BaseController {
    private Logger log = LoggerFactory.getLogger("baseController");
    /**
     * 获取请求头信息中的用户编号
     * @param request http请求
     * @return
     */
    public int getUid(HttpServletRequest request){
        //根据请求对象获取头信息, 参数是 uid
        String header = request.getHeader(CacheConstant.HEADER_UID);
        log.info("header:"+header);
        //如果头信息中存在则转换为整型
        if(StringUtils.hasText(header)){
            return Integer.parseInt(header);
        }
        return 0;
    }
}
